
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>谈谈Redis Cluster模式 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>谈谈Redis Cluster模式 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">Redis Cluster模式通过什么核心机制来实现负载均衡和高可用性？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Redis Cluster模式通过数据分片和分布式存储来实现负载均衡和高可用性。它将所有键值对数据分散在多个节点上，每个节点负责一部分数据（槽位），从而突破单节点的内存限制。</div>
          </div>
          <div class="card-source">来源: 文档开篇介绍</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Redis Cluster是如何对整个数据集进行划分的？总共划分了多少个单位？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Redis Cluster将整个数据集划分为16384个哈希槽（hash slots）。这些槽被均匀地分布在集群中的各个主节点上，每个节点负责管理一部分槽。</div>
          </div>
          <div class="card-source">来源: RedisCluster原理</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">Redis Cluster使用什么算法来确定一个给定的键（key）应该映射到哪个槽位？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Redis Cluster使用CRC16算法计算键的哈希值，然后对16384进行取模运算（CRC16(key) % 16384），从而得到该键对应的槽位编号。</div>
          </div>
          <div class="card-source">来源: 数据分片与槽位</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Redis Cluster中的节点之间是如何进行通信和共享信息的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">节点之间使用gossip协议进行通信，通过集群总线（cluster bus）来共享集群信息，例如节点拓扑、槽的分配情况等。这是一种去中心化的通信方式。</div>
          </div>
          <div class="card-source">来源: 总结 > 节点之间的通信</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">Redis Cluster如何保证高可用性？当一个主节点失效时会发生什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">通过主从复制机制来保证高可用性。每个哈希槽对应一个主节点和零个或多个从节点。当主节点不可用时，集群会通过投票选举机制从其从节点中选出一个新的主节点，从而实现自动故障恢复。</div>
          </div>
          <div class="card-source">来源: 总结 > 主从复制 / 投票选举</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在Redis Cluster中，客户端是如何找到存储特定键值的正确节点的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">客户端首先通过哈希算法（CRC16(key) % 16384）计算出键对应的哈希槽，然后根据本地缓存的槽位分配信息，直接与负责该槽位的节点进行通信，无需中心节点的介入。</div>
          </div>
          <div class="card-source">来源: 总结 > 客户端的路由</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在创建Redis集群的命令中，`--cluster-replicas 1`参数的作用是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">该参数用于指定每个主节点的从节点数量。`--cluster-replicas 1`表示为每个创建的主节点都分配一个从节点。</div>
          </div>
          <div class="card-source">来源: 配置和实现</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">当Redis Cluster的节点数量发生变化（如添加或删除节点）时，集群会如何响应？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当集群中的节点变化或槽的分配发生变化时，Redis Cluster会自动触发数据迁移。这包括源节点和目标节点之间的数据同步以及槽的重新分配，以确保集群的负载均衡。</div>
          </div>
          <div class="card-source">来源: 总结 > 数据迁移和负载均衡</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">应用</div>
          <div class="card-question">根据文档，Redis Cluster适用于哪些典型的应用场景？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">应用</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">1. 大规模数据存储：通过数据分片突破单节点内存限制。<br>2. 高性能要求场景：通过负载均衡提高系统性能。<br>3. 高可用性要求场景：通过自动故障转移确保服务持续可用。</div>
          </div>
          <div class="card-source">来源: 场景应用</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
